package com.inspection.controller;

import com.inspection.constant.YesNoEnum;
import com.inspection.entity.InspectionDepartmentDO;
import com.inspection.model.dto.InspectionDepartmentDTO;
import com.inspection.model.dto.InspectionDepartmentQueryDTO;
import com.inspection.service.InspectionDepartmentService;
import com.inspection.support.Wrapper;
import com.inspection.support.anno.SysLogAnno;
import com.inspection.support.model.ItemList;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author : chenjx
 * create at:  2020/11/8  6:59 下午
 */
@RestController
public class InspectionDepartmentController {

    @Autowired
    private InspectionDepartmentService inspectionDepartmentService;

    @ApiOperation("获取部门列表 只能获取所有的叶子节点")
    @RequestMapping("/inspect/department/query")
    public Wrapper<ItemList<InspectionDepartmentDO>> queryDepartment(@RequestBody InspectionDepartmentQueryDTO query) {

        return Wrapper.ok(ItemList.buildItems(inspectionDepartmentService.queryDepartment(query)));
    }

    @SysLogAnno(operateCode =110301,operateName = "部门：保存")
    @ApiOperation("保存部门")
    @RequestMapping("/inspect/department/save")
    public Wrapper<String> saveDepartment(@RequestBody InspectionDepartmentDTO save){
        inspectionDepartmentService.saveDepartment(save);
        return  Wrapper.ok("ok");
    }



    @SysLogAnno(operateCode =110302,operateName = "部门：删除")
    @ApiOperation("删除部门")
    @RequestMapping("/inspect/department/del")
    public Wrapper<String> delDepartment(@RequestBody InspectionDepartmentDTO del){
        inspectionDepartmentService.delDepartment(del);
        return  Wrapper.ok("ok");
    }
    @ApiOperation("获取部门")
    @RequestMapping("/inspect/department/get")
    public Wrapper<InspectionDepartmentDO> getDepartment(@RequestBody InspectionDepartmentQueryDTO query){

        return  Wrapper.ok(inspectionDepartmentService.getDepartment(query));
    }

    @SysLogAnno(operateCode =110303,operateName = "部门：更新")
    @ApiOperation("更新部门")
    @RequestMapping("/inspect/department/update")
    public Wrapper<String> updateDepartment(@RequestBody InspectionDepartmentDTO update){
        inspectionDepartmentService.updateDepartment(update);
        return  Wrapper.ok("ok");
    }
}
